package action.util;

import action.newelifile.R;
import action.pojo.Setting;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable;
import android.widget.LinearLayout;


public class LoadSetting {
	public static Setting setting;

	public static void load(Context context) {
		DatabaseHelper dbhelper = new DatabaseHelper(context);
		setting = new Setting();
		setting.setBackground(0);
		setting.setDisplay(1);
		try {
			SQLiteDatabase db = dbhelper.getWritableDatabase();
			String query = "select * from " + DatabaseHelper.TABLE_NAME
					+ " where " + DatabaseHelper.ID + " = " + 1;
			Cursor cursor = db.rawQuery(query, null);
			while (cursor.moveToNext()) {
				setting.setId(cursor.getInt(0));
				setting.setBackground(cursor.getInt(2));
				setting.setDisplay(cursor.getInt(1));
				setting.setLanguage(cursor.getInt(3));
				setting.setIcon(cursor.getInt(4));
			}			
			cursor.close();
			db.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void loadTheme(Activity activity){
		switch (setting.getBackground()){
			case 0:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundColor(activity.getResources().getColor(R.color.main_background));
				break;
			case 1:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.hinh1));
				break;
			case 2:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.hinh2));
				break;
			case 3:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.hinh3));
				break;
			case 4:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.hinh4));
				break;
			case 5:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.hinh5));
				break;
			case 6:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.hbiencat));
				break;
			case 7:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.htim));
				break;
			case 8:
				((LinearLayout)activity.findViewById(R.id.main)).setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.hxam));
				break;
		}
	}
	
	public static Drawable loadFolder(Activity activity){
		Drawable dr = null;
		switch (setting.getIcon()){
			case 0:
				dr= activity.getResources().getDrawable(
						R.drawable.folder1);
				break;
			case 1:
				dr= activity.getResources().getDrawable(
						R.drawable.folder2);
				break;
			case 2:
				dr= activity.getResources().getDrawable(
						R.drawable.folder3);
				break;
			case 3:
				dr= activity.getResources().getDrawable(
						R.drawable.folder4);
				break;
		}
		return dr;
	}
	
}
